﻿using System;
using System.Reflection;
using Infrastructure.Logging;

namespace MediaController.Client.DAL
{
    public static class Logger
    {
        /// <summary>
        /// logger
        /// </summary>
        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public static event Action<string> NewLogMessage;

        public static void Log(string msg)
        {
            using (var opp = new OperationDC("Loggin Message"))
            {
                log.Debug(msg);
                string newMsg = string.Format("[{0}]: {1}", DateTime.Now, msg);
                InvokeNewLogMessage(newMsg);
                opp.Successful = true;
            }
        }

        private static void InvokeNewLogMessage(string msg)
        {
            Action<string> handler = NewLogMessage;
            if (handler != null) handler(msg);
        }
    }
}